
import { Node, _decorator } from "cc";
import { BaseUI } from "../../framework/base/BaseUI";
import { SDKMgr } from "../../framework/manager/SDKMgr";
import { UIMgr } from "../../framework/manager/UIMgr";
import { UIID } from "../config/Config";
import { GameDef } from "../gameLogic/GameDef";
import { GameLogicMgr } from "../gameLogic/GameLogicMgr";
const { ccclass, property } = _decorator;

@ccclass('UIExitGame')
export class UIExitGame extends BaseUI {

    /**底部节点 */
    @property(Node)
    downNode: Node = null;

    //是否正在游戏
    isGaming: boolean = false;

    callback: Function = null;
    public init(param1?: any, param2?: any, param3?: any, param4?: any, param5?: any): void {
        this.isGaming = UIMgr.getInstance().getUIById(UIID.UIGame) != null// GameMgr.getInstance().getGameState()
    }

    start() {
        this.initView();
    }

    initView() {
        this.findChilds("btnClose").on('click', this.closeBtn, this)
        this.findChilds("backHomeToBtn").on('click', this.clickHome, this)
    }
    closeBtn() {
        this.closeUI();
        this.isGaming && GameLogicMgr.instance.resumeGame();
    }
    clickHome() {
        this.closeUI();
        UIMgr.getInstance().closeById(UIID.UIGame);
        UIMgr.getInstance().openUI(UIID.UIHome, UIID.Default);
        this.isGaming && GameLogicMgr.instance.resumeGame();
        this.report();
    }

    report() {
        SDKMgr.getInstance().reportEvent("exitstage", {
            "level_type": "主线",
            "stage": `第${GameDef.instance.curLevel}关`,
            "passstage": 0,
            "exit_info": "中途退出",
            "revivetime": GameDef.instance.reportInfo.revivetime,
            "tip": GameDef.instance.reportInfo.tip,
            "refresh": GameDef.instance.reportInfo.refresh,
            "knock": GameDef.instance.reportInfo.knock,
            "passpercent": GameDef.instance.reportInfo.levelPorgress,
            "points": GameDef.instance.currLevelTotalPoints,
            "ad_video_times": GameDef.instance.reportInfo.ad_video_times,
            "max_combo": GameDef.instance.comboCount,
        })
    }

}
